package com.cnfangmao.masterdata.controller;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.propertyeditors.PropertiesEditor;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.cnfangmao.masterdata.model.AccountBasicDataRight;
import com.cnfangmao.masterdata.service.AccountBasicDataRightService;

/**
 * <p>
 * 用户主数据权限表 前端控制器
 * </p>
 *
 * @author chenxd
 * @since 2020-04-14
 */
@RestController
@RequestMapping("/accountBasicDataRight")
public class AccountBasicDataRightController {

	private static final Logger logger = LoggerFactory.getLogger(AccountBasicDataRightController.class);

	@Autowired
	private AccountBasicDataRightService accountBasicDataRightService;

	@PostMapping(value = "/create.api")
	public void doCreate(@ModelAttribute("accountBasicDataRight") AccountBasicDataRight accountBasicDataRight) {
		logger.info("accountBasicDataRight.userId = " + accountBasicDataRight.getUserId());
		logger.info("accountBasicDataRight.metadataId = " + accountBasicDataRight.getMetadataId());
		logger.info("accountBasicDataRight.rightList = " + accountBasicDataRight.getRightList());
	}

	@GetMapping(value = "/edit.api")
	public void edit(@RequestParam("rightId") String rightId) {
		AccountBasicDataRight accountBasicDataRight = accountBasicDataRightService.getById(rightId);

		logger.info("accountBasicDataRight.userId = " + accountBasicDataRight.getUserId());
		logger.info("accountBasicDataRight.metadataId = " + accountBasicDataRight.getMetadataId());
		logger.info("accountBasicDataRight.rightList = " + accountBasicDataRight.getRightList());
	}

	@PostMapping(value = "/update.api")
	public void update() {
	}
	
	@PostMapping(value = "/delete.api")
	public void delete(@RequestParam("rightIds[]") String[] rightIds) {
		for(String rightId : rightIds) {
			logger.info("accountBasicDataRight.userId = " + rightId);
		}
	}

	/**
	 * Inits the binder.
	 *
	 * @param binder the binder
	 */
	@InitBinder
	public void initBinder(WebDataBinder binder) {
		binder.registerCustomEditor(String.class, new PropertiesEditor());
	}
}
